<?php
class ModelModuleTDGiftonorder extends Model {
	public function addGift($data){
		$this->db->query("INSERT INTO " . DB_PREFIX . "td_giftonorder SET name = '" . $data['name'] . "', options = '" . $this->db->escape(base64_encode(serialize($data['options']))) . "', date_start='".$data['date_start']."', date_end='".$data['date_end']."'");
	}
	public function deleteGift($id){
		$this->db->query("DELETE FROM " . DB_PREFIX . "td_giftonorder WHERE id='".$id."'");
	}
	public function getGifts(){
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "td_giftonorder");
		return $query->rows ? $query->rows : false;
	}
	public function getGift($id){
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "td_giftonorder WHERE id='".$id."'");
		return $query->row ? $query->row : false;
	}
	public function editGift($data){
		$this->db->query("UPDATE " . DB_PREFIX . "td_giftonorder SET name = '" . $data['name'] . "', options = '" . $this->db->escape(base64_encode(serialize($data['options']))) . "' , date_start='".$data['date_start']."', date_end='".$data['date_end']."' WHERE id='".$data['id']."'");
	}
    public function tdGiftInstall() {
		$query = $this->db->query("CREATE TABLE IF NOT EXISTS ".DB_PREFIX."td_giftonorder
			(
				id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
				name VARCHAR(128) NOT NULL,
				options TEXT NOT NULL,
				date_start DATE NOT NULL,
				date_end DATE NOT NULL
			) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci");
	}
}
?>